package org.lanqiao.tjut.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.EmployeeBean;
import org.lanqiao.tjut.model.ModelFactory;
import org.lanqiao.tjut.myUtils.MyUtils;

import com.alibaba.fastjson.JSON;

/**
 * 删除操作 EmployeeInfoDeleteServlet
 */
@WebServlet("/EmployeeInfoDeleteServlet")
public class EmployeeInfoDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 获取删除记录的id
		String delIndex = request.getParameter("delIndex");
		System.out.println(delIndex);
		//如果删除记录不为null则进行删除操作
		if(delIndex != null && !delIndex.equals("")){
			//调用model层进行删除操作
			ModelFactory.getEmployeeInfoAddModelInstance().deleteEmployeeInfoById(delIndex);
		}
		// 查询操作
				EmployeeBean empB = MyUtils.convertRequest2Bean(request, EmployeeBean.class, null, null);
				List<EmployeeBean> lstEmps = ModelFactory.getEmployeeInfoAddModelInstance().queryEmployeeInfoByParams(empB);
				String strJson = JSON.toJSONStringWithDateFormat(lstEmps,"yyyy-MM-dd HH:mm:ss");
				//使用writer对象将服务器响应内容写到客户端
				PrintWriter pw = response.getWriter();
				pw.write(strJson);
				pw.flush();
				pw.close();
				}

	
}
